package com.lagou.thread;

import org.apache.zookeeper.KeeperException;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class TimeThread extends Thread {

    private String path;

    public TimeThread(String path) {
        this.path = path;
    }

    @Override
    public void run() {
//        updateServerTime();
    }

    /**
     * 更新服务端的时间
     */
//    private static void updateServerTime() {
//        ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
//        executorService.scheduleAtFixedRate(() -> {
//
//            String path = "/" + NAMESPACE + IP + ":" + PORT;
//            System.out.println("定时任务开始执行：" + System.currentTimeMillis());
//            String noteData = null;
//            try {
//                noteData = getNoteData(path);
//                if (System.currentTimeMillis() - Long.parseLong(noteData) > 5000) {
//                    setNoteData(path, String.valueOf(System.currentTimeMillis()));
//                }
//            } catch (KeeperException e) {
//                e.printStackTrace();
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }, 0, 5, TimeUnit.SECONDS);
//    }
}
